package no.ntnu.fp.services.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import no.ntnu.fp.model.MeetingRoom;
import no.ntnu.fp.services.MeetingRoomService;
import no.ntnu.fp.storage.MeetingRoomStorage;
import no.ntnu.fp.utils.MeetingRoomSchedule;
import no.ntnu.fp.utils.TimeInterval;

public class MeetingRoomServiceImpl extends EntityServiceImpl<MeetingRoom> 
												implements MeetingRoomService {
	
	private final MeetingRoomStorage meetingRoomStorage;

	public MeetingRoomServiceImpl(MeetingRoomStorage meetingRoomStorageImpl) {
		this.meetingRoomStorage = meetingRoomStorageImpl;
	}

	@Override
	public MeetingRoomSchedule getMeetingRoomSchedule() {
		List<MeetingRoom> rooms = meetingRoomStorage.getAllMeetingRooms();
		Map<MeetingRoom, List<TimeInterval>> bookingMap
			= new HashMap<MeetingRoom, List<TimeInterval>>();
		
		for (MeetingRoom room: rooms) {
			List<TimeInterval> bookings = meetingRoomStorage.getBookings(room);
			bookingMap.put(room, bookings);
		}
		
		return new MeetingRoomSchedule(bookingMap);
	}
}
